//
//  BVSearchViewController.h
//  AssistantCloud1
//
//  Created by YYKJ on 2017/4/17.
//  Copyright © 2017年 YYKJ. All rights reserved.
//

#import "BVUser.h"

#define USER_DEFAULTS_USER_ID        @"user_id"
#define USER_DEFAULTS_NICK_NAME      @"nick_name"
#define USER_DETAULTS_MOBILE         @"mobile"
#define USER_DEFAULTS_ADDRESS        @"address"

@interface BVUser()

@property (nonatomic, strong)NSUserDefaults *userDefaults;

@end


@implementation BVUser

#pragma mark -
#pragma mark - Singleton User
- (NSUserDefaults *)userDefaults {
    if (!_userDefaults) {
        _userDefaults = [NSUserDefaults standardUserDefaults];
    }
    return _userDefaults;
}

+ (BVUser *)sharedUser {
    static BVUser *sharedUserInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedUserInstance = [[BVUser alloc] init];
    });
    return sharedUserInstance;
}

#pragma mark -
#pragma mark Property Setter And Getter
- (NSString *)user_id {
    return [self.userDefaults objectForKey:USER_DEFAULTS_USER_ID];
}

- (void)setUser_id:(NSString *)user_id {
    [self.userDefaults setObject:user_id forKey:USER_DEFAULTS_USER_ID];
}

- (NSString *)nick_name{
    return [self.userDefaults objectForKey:USER_DEFAULTS_NICK_NAME];
}

- (void)setNick_name:(NSString *)nick_name{
    [self.userDefaults setObject:nick_name forKey:USER_DEFAULTS_NICK_NAME];
}

- (NSString *)mobile {
    return [self.userDefaults objectForKey:USER_DETAULTS_MOBILE];
}

- (void)setMobile:(NSString *)mobile {
    [self.userDefaults setObject:mobile forKey:USER_DETAULTS_MOBILE];
}


- (NSString *)address {
    return [self.userDefaults objectForKey:USER_DEFAULTS_ADDRESS];
}

- (void)setAddress:(NSString *)address {
    [self.userDefaults setObject:address forKey:USER_DEFAULTS_ADDRESS];
}


- (BOOL)isLogin {
    
    return self.user_id ? YES : NO;
}

- (void)logout {
    
    [self.userDefaults setObject:nil forKey:USER_DEFAULTS_USER_ID];
    [self.userDefaults setObject:nil forKey:USER_DEFAULTS_NICK_NAME];
    [self.userDefaults setObject:nil forKey:USER_DETAULTS_MOBILE];
    [self.userDefaults setObject:nil forKey:USER_DEFAULTS_ADDRESS];
   
}

@end
